<?php
header('Content-Type:text/html;Charset=UTF-8');

@$name = $_REQUEST['name'];
@$price = $_REQUEST['price'];
@$typeId = $_REQUEST['typeId'];
@$mode = $_REQUEST['mode'];
@$purchase = $_REQUEST['purchase'];

@$img = $_FILES['img'];

$message="";

if($typeId=='可选择类型'){
	$message=("类型必须选定");
}

if(empty($img['name'])){
	$message=("照片必须选定");
}

if($img['error']!=0){
	$message=("照片上传出错");
}

$flag = move_uploaded_file($img['tmp_name'],'img/'.$img['name']);

if(!$flag){
	$message=("照片上传失败");
}

if(empty($name)||empty($price)||empty($mode)||empty($purchase)){
	$message=('不能为空,请重新进货商品！');
}
require 'lib/db.php';

@$flag = dbInsert("insert into entry(name,price,imgUrl,mode,purchase,typeId) values(:name,:price,:imgUrl,:mode,:purchase,:typeId)",array('name'=>$name,'price'=>$price,'imgUrl'=>$img['name'],'mode'=>$mode,'purchase'=>$purchase,'typeId'=>$typeId));

if($flag){
	header('Refresh:1;url=/merchandiseDish.php');
	$message=('<h3>商品进货成功！</h3>');
}else{
	header('Refresh:1;url=/merchandiseDish.php');
	$message=('<h3>商品进货失败！</h3>');
}

// @$entry = dbSelect('select id,name price,typeId from entry',array('name'=>$name,'price'=>$price));
?>
<!DOCTYPE html>
<html>
   <head>
      <title>SuperMarket</title>
	  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" charset="UTF-8" >
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <script src="bootstrap/js/jquery-1.11.1.min.js"></script>
      <script src="bootstrap/js/bootstrap.min.js"></script>
      <!--[if lt IE 9]>
         <script src="js/html5shiv.js"></script>
         <script src="js/respond.min.js"></script>
      <![endif]-->
   </head>
   <style>
   #color{color:red}
   .size{width:350px;height:100px}
   </style>
<body>
   
   <div class="row">
   	<div class="col-xs-4 col-xs-offset-4 size">
   		<div class="modal-content">
   			<div class="modal-header">
				<div class="modal-title">
				<h3 id="color">提示</h3>
				</div>			
			</div>
				<div class="modal-body">
					<?php echo $message;?>
				</div>
				<div class="modal-footer">
						<a href="Addmerchandise.php" class="btn btn-primary">知道了</a>
				</div>
   		</div>
   	</div>
   </div>
   
</body>
   </html>



